home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / DEMOS / DEMOSTUF.ZIP / STARS1.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-07-25  |  3.4 KB  |  220 lines

  1. program assemblerguf;
  2. {
  3.     Stars #1
  4.     - by Bjarke Visφe
  5.     nov 1993
  6.  
  7.     Really old stuff, this one.
  8.     Tampered on Lyngby EDB-skoles computer... a 16mhz 386! (shiiiit...)
  9. }
  10.  
  11. uses
  12.     DEMOINIT;
  13.  
  14. const
  15.     width = 320;
  16.     stars = 1400;
  17.  
  18. type
  19.     coord = record
  20.         x,y,z : integer;
  21.     end;
  22.  
  23. var
  24.     oldmode, oldpage    : shortint;
  25.     taller                : integer;
  26.     ytabel                : array [0..255] of integer;
  27.     sinustabel            : array [0..639] of integer;
  28.  
  29.     i, j : integer;
  30.  
  31.     StarXY                : array [1..stars] of coord;
  32.     ClearTabel            : array [1..stars] of coord;
  33.  
  34.     starpos                : integer;
  35.     starcount            : integer;
  36.     vinkelx, vinkely, vinkelz : integer;
  37.     vxadd, vyadd, vzadd    : integer;
  38.  
  39.  
  40. (*-----------------------------------------------------------*)
  41.  
  42.  
  43. procedure setupsinus;
  44. var
  45.     i : integer;
  46.     v, vadd : real;
  47. begin
  48.     v:=0.0;
  49.     vadd:=(2.0*pi/512.0);
  50.     for i:=0 to 639 do
  51.     begin
  52.         sinustabel[i]:=round(sin(v)*32767);
  53.         v:=v+vadd;
  54.     end;
  55. end;
  56.  
  57.  
  58. procedure SetupCoords;
  59. var
  60.     i : integer;
  61. begin
  62.     for i:=1 to stars do    with ClearTabel[i] do begin
  63.         x:=0; y:=0; z:=0;
  64.     end;
  65.  
  66.     randomize;
  67.     for i:=1 to stars do
  68.         with starXY[i] do begin
  69.             x := random(65535)-$8000;
  70.             y := random(65535)-$8000;
  71.             z := random(512);
  72.         end;
  73. end;
  74.  
  75.  
  76. procedure SetupDemo;
  77. var
  78.     i : integer;
  79. begin
  80.     vinkelx:=0; vinkely:=0; vinkelz:=0;
  81.     SetupSinus;
  82.     SetupCoords;
  83.  
  84.     for i:=0 to 255 do ytabel[i]:=i*width;
  85. end;
  86.  
  87.  
  88. (*-----------------------------------------------------------*)
  89.  
  90. procedure OpenScreen;
  91. var
  92.    i, color : integer;
  93. begin
  94.     asm
  95.         mov     ah,$0F
  96.         int     $10
  97.         mov     oldmode,al
  98.  
  99.         mov     al,$13
  100.         xor     ah,ah
  101.         int     $10
  102.      end;
  103.  
  104.      color := 64;
  105.      for i:=0 to 63 do
  106.      begin
  107.         SetRGB(i, color,color,color);
  108.         dec(color);
  109.      end;
  110. end;
  111.  
  112. procedure CloseScreen;
  113. begin
  114.     asm
  115.         mov    al,oldmode
  116.         xor    ah,ah
  117.         int    $10
  118.     end;
  119. end;
  120.  
  121.  
  122. (*-----------------------------------------------------------*)
  123.  
  124. procedure SetVinkel;
  125. begin
  126.     vinkelx:=(vinkelx+1) mod 512;
  127.     vinkely:=(vinkely+1) mod 512;
  128.     vinkelz:=(vinkelz+2) mod 512;
  129.  
  130.     vxadd:=sinustabel[vinkelx]*3;
  131.     vyadd:=sinustabel[vinkely]*3;
  132.     vzadd:=sinustabel[vinkelz] DIV 180;
  133. end;
  134.  
  135.  
  136. procedure ClearStars;
  137. begin
  138.    asm
  139.     mov     ax,SEGA000
  140.     mov     es,ax
  141.     lea     si,ClearTabel           {point at record array}
  142.     mov     ax,6                    {record size}
  143.     xor     dl,dl
  144.     mov     cx,stars
  145. @ClearLoop:
  146.     mov     bx,[si]
  147.     mov     [es:bx],dl
  148.     add     si,ax
  149.     loop    @ClearLoop
  150.     end;
  151. end;
  152.  
  153.  
  154. procedure PlotStars;
  155. begin
  156.     starcount := stars;
  157.     starpos := 0;
  158.  
  159.     asm
  160.     mov     ax,SEGA000
  161.     mov     es,ax
  162. @starloop:
  163.     lea     si,starXY
  164.     add     si,starpos
  165.     mov     bx,[si]
  166.     mov     ax,[si+2]
  167.     mov     cx,[si+4]
  168.     add     bx,vxadd
  169.     add     ax,vyadd
  170.     add     cx,vzadd
  171.     and     cx,511
  172.     inc     cx
  173.  
  174.     cwd
  175.     idiv    cx
  176.     xchg    bx,ax
  177.     cwd
  178.     idiv    cx
  179.     add     ax,160
  180.     cmp     ax,319
  181.     ja      @StarLoopAgain
  182.     add     bx,100
  183.     cmp     bx,199
  184.     ja      @StarLoopAgain
  185.  
  186.     shl      bx,1
  187.     add      bx,OFFSET ytabel
  188.     mov     bx,[bx]
  189.     add     bx,ax
  190.     lea     si,ClearTabel
  191.     add     si,starpos
  192.     mov     [si],bx
  193.  
  194.     shr     cx,3
  195.     and     cl,63
  196.     mov     [es:bx],cl
  197. @StarLoopAgain:
  198.     add     starpos,6
  199.     dec     StarCount
  200.     jnz     @StarLoop
  201.     end;
  202. end;
  203.  
  204.  
  205. (*-----------------------------------------------------------*)
  206.  
  207. begin
  208.     SetupDemo;
  209.     OpenScreen;
  210.  
  211.     while (not keypressed) do begin
  212.         VBLANK;
  213.         ClearStars;
  214.         PlotStars;
  215.         SetVinkel;
  216.     end;
  217.  
  218.     CloseScreen;
  219. end.
  220.